package com.kaifamiao.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 面试常问问题:
 *    HTTP请求中 GET请求 与 POST请求 的区别是什么？
 */
@WebServlet( name = "dispatcher", urlPatterns = {"/dispatcher","/dispatcher/*"} )
public class DispatcherServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.log( "[" + this + "]接收到GET请求" );
        response.setContentType( "text/html" );
        response.getWriter().println( "<h1>I am a DispatcherServlet instance.</h1>" );
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.log( "[" + this + "]接收到POST请求" );
        response.setContentType( "text/html" );
        response.getWriter().println( "<h1>I am a DispatcherServlet instance.</h1>" );
    }

}
